#include "MenuBar.h"
#include "menubar.h"

#include <QAction>
#include <QIcon>

static QAction *newAction(const QString &txt, QMenu *parent, QAction *&act, bool autoRepeat, const QIcon &icon, bool checkable, QAction::MenuRole role = QAction::NoRole)
{
    act = new QAction(txt, parent);
    act->setAutoRepeat(autoRepeat);
    act->setCheckable(checkable);
    parent->addAction(act);
    act->setMenuRole(role);
    act->setIcon(icon);
    return act;
}

MenuBar::MenuBar()
{
	addMenu(window = new Window(this));
	addMenu(games = new Games(this));
	addMenu(help = new Help(this));
}

MenuBar::Window::Window(MenuBar *parent) :
    QMenu(Window::tr("&窗口"), parent)
{
    newAction(Window::tr("&关闭"), this, close, false, QIcon(), false, QAction::QuitRole);
}

MenuBar::Games::Games(MenuBar *parent) :
    QMenu(Games::tr("&游戏"), parent)
{
    newAction(Games::tr("&成语接龙"), this,  wordsSolitaire, false, QIcon(), false);
    newAction(Games::tr("&你比划我猜"), this, showAndGuess, false, QIcon(), false);
}

MenuBar::Help::Help(MenuBar *parent) :
    QMenu(Help::tr("&帮助"), parent)
{
    newAction(Help::tr("&关于"), this, about, false, QIcon(), false, QAction::AboutRole);
}
